/*
 * @Description: 计划
 * @Author: Zzt
 * @Date: 2022-08-12 14:30:53
 * @LastEditTime: 2022-08-15 11:04:18
 */

import {
  SET_SELECT_AT,
  SET_SELECT_AT_ID,
  SET_SELECT_FOND_ID,
  SET_TRANSFER_LIST,
  DELETE_PLAN_ITEM,
  SET_SELECTED_ITEM
} from '../constants';
import { delItemByIdArray } from '@/utils/list';

export const BackupPlanReducer = (state, action) => {
  switch (action.type) {
    /**
     * @description: 设置选中的全宗
     */
    case SET_SELECT_FOND_ID:
      return {
        ...state,
        selectFondId: action.id
      };

    /**
     * @description: 设置选中的档案类型
     */
    case SET_SELECT_AT:
      return {
        ...state,
        selectAT: action.data
      };

    /**
     * @description: 设置选中的档案类型
     */
    case SET_SELECT_AT_ID: {
      return {
        ...state,
        selectATId: action.id
      };
    }
    // 设置移交清单列表
    case SET_TRANSFER_LIST:
      return {
        ...state,
        transferList: action.data
      };
    // 删除计划
    case SET_SELECTED_ITEM:
      return { ...state, delId: action.data };
    case DELETE_PLAN_ITEM: {
      console.log('del_export', action.ids);
      return {
        ...state,
        plan: delItemByIdArray(action.ids, state.plan)
      };
    }

    default:
      console.log('untouched', action);
      return state;
  }
};
